package main

import (
    "fmt"
    "net/http"
    "io/ioutil"
    "strings"
)

func main() {
    res, _ := analysisCategory()
    for k, v := range res {
        fmt.Println(k, " : ", v)
    }
}

func test() {
}

func analysisCategory() ([]string, error) {
    resp, err := http.Get("http://en.bookfi.org/categories")
    if err != nil {
        return nil, err
    }
    body, _ := ioutil.ReadAll(resp.Body)
    page := string(body)

    var res []string
    sH2 := page[:]
    for {
        n := strings.Index(sH2, "padding:0 0 20px 0")
        if n == -1 {
            break
        }
        sH2 = sH2[n+1:]
        ul1 := strings.Index(sH2, "<ul>")
        ul2 := strings.Index(sH2, "</ul>")
        ul := sH2[ul1 : ul2]
        for {
            nHref := strings.Index(ul, "<a href")
            if nHref == -1 {
                break
            }
            ul = ul[nHref+9:]
            urlEnd := strings.Index(ul, "\"")
            url := ul[:urlEnd]
            /*
            categoryStart := strings.Index(ul, ">")
            categoryEnd := strings.Index(ul, "<")
            category := ul[categoryStart+1 : categoryEnd]
            */
            res = append(res, url)
        }
    }
    fmt.Println(len(res))
    return res, nil
}
